<?php
/**
 * author by OCY, 2022/01/19 16:09.
 */

namespace app\index\controller;

use mikkle\tp_redis\Redis;
use think\Request;

class Music
{
    public function searchMusic()
    {
        $url = 'https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=%E5%90%8E%E6%9D%A5%E7%9A%84%E4%BD%A0%E5%9C%A8%E5%93%AA%20%E6%A0%91%E6%B3%BD&pn=1&rn=20';

        $header = [
            'Accept' => 'application/json, text/plain, */*',
            'Accept-Encoding' => 'gzip, deflate, br',
            'Accept-Language' => 'zh-CN,zh;q=0.9',
            'Connection' => 'keep-alive',
            'Cookie' => 'kw_token=BTTT4LFQW8',
            'csrf' => 'BTTT4LFQW8',
            'Host' => 'www.kuwo.cn',
            'origin' => 'https://www.kuwo.cn/',
            'referer' => 'https://www.kuwo.cn/',
            'sec-ch-ua' => '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
            'sec-ch-ua-mobile' => '?0',
            'sec-ch-ua-platform' => '"Windows"',
            'Sec-Fetch-Dest' => 'empty',
            'Sec-Fetch-Mode' => 'cors',
            'Sec-Fetch-Site' => 'none',
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
        ];

        $res = httpsRequest($url, null, $header);
        echo "<pre>";
        print_r($res);
        exit;
    }

    public function test()
    {
        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_URL => "https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=后来的你在哪 树泽&pn=1&rn=20",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_HTTPHEADER => [
                "Accept: application/json, text/plain, */*",
                "Accept-Encoding: gzip, deflate, br",
                "Accept-Language: zh-CN,zh;q=0.9",
                "Connection: keep-alive",
                "Cookie: kw_token=BTTT4LFQW8",
                "Host: www.kuwo.cn",
                "Sec-Fetch-Dest: empty",
                "Sec-Fetch-Mode: cors",
                "Sec-Fetch-Site: none",
                "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",
                "csrf: BTTT4LFQW8",
                "origin: https://www.kuwo.cn/",
                "referer: https://www.kuwo.cn/",
                '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
                "sec-ch-ua-mobile: ?0",
                "sec-ch-ua-platform: Windows"
            ],
        ]);

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            echo "cURL Error #:" . $err;
        } else {
            echo $response;
        }
    }

    public function listen1Like()
    {
        $url = 'https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=%E5%90%8E%E6%9D%A5%E7%9A%84%E4%BD%A0%E5%9C%A8%E5%93%AA%20%E6%A0%91%E6%B3%BD&pn=1&rn=20';

        $header = [
            'accept' => 'application/json, text/plain, */*',
            'accept-encoding' => 'gzip, deflate, br',
            'accept-language' => 'zh-CN,zh;q=0.9',
            'cookie' => 'RK=qt+ZijGQPW; ptcz=02da3095d00eb8599d9560b09fb21c530d67689f731bb002cf797edca40143c5; pgv_pvid=7591674412; fqm_pvqid=e0c8d826-a348-44c7-a512-df98d374958f; fqm_sessionid=48efd63e-0ff3-46fb-bb4c-eed035d01fd9; pgv_info=ssid=s1090217728; ts_uid=7233183528; _qpsvr_localtk=0.43813313798764586; login_type=1; psrf_qqrefresh_token=25A1008EC95CD013BF069EC2DBA8764B; psrf_qqaccess_token=D7066BF4EAE6D73A38F899D67F15892D; psrf_access_token_expiresAt=1676253125; qm_keyst=Q_H_L_5TMRjeIjGo8q9QTuD1ztJBYWyz7_nmjVIR7oPqV_ZLeKcVn82zghCfA; qqmusic_key=Q_H_L_5TMRjeIjGo8q9QTuD1ztJBYWyz7_nmjVIR7oPqV_ZLeKcVn82zghCfA; tmeLoginType=2; euin=oK6lowSA7i4Aoz**; uin=1172727523; wxrefresh_token=; qm_keyst=Q_H_L_5TMRjeIjGo8q9QTuD1ztJBYWyz7_nmjVIR7oPqV_ZLeKcVn82zghCfA; psrf_musickey_createtime=1668477125; psrf_qqunionid=591634DDBF05DD1679CD444C235389F2; wxopenid=; wxunionid=; psrf_qqopenid=D5336018D0AE1B46F5A808AB8F635A7C; ts_last=y.qq.com/n/ryqq/player',
            'origin' => 'https://y.qq.com/',
            'referer' => 'https://y.qq.com/',
            'sec-ch-ua' => '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
            'sec-ch-ua-mobile' => '?0',
            'sec-ch-ua-platform' => '"Windows"',
            'sec-fetch-dest' => 'empty',
            'sec-fetch-mode' => 'cors',
            'sec-fetch-site' => 'none',
            'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
        ];

        $res = httpsRequest($url, null, $header);
        echo "<pre>";
        print_r($res);
        exit;
    }


    public function test1()
    {
        apiReturn(1, '成功', 1223443);
    }

    public function test2()
    {
        $input = Request()->param();

        $a = $input['a'];

        file_put_contents(RUNTIME_PATH . 'test.txt', $a);
    }

}